using UnityEngine;
using System.Collections;

public class GameManager : MonoBehaviour 
{	
	public GUIText bankHP;
	public GUIText wave;
	public GUIText enemyKill;
    public GUIText money;

    public SpawnManager spawnManager;
    public Stats stats;
    private Player player;

    public int _money;
	public int _hp;
	public int _wave;
	public int _enemy;
	public int _maxEnemy;

    void Start()
    {
        player = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>();
        _hp = 100 + (player.cStats.vitality * (200 / 99));

        spawnManager.run();
    }

	void Update () 
	{
        //print(_hp);
		bankHP.text = "Bank: " + _hp + "%";
		wave.text = "Wave: " + _wave;
		enemyKill.text = "Enemies: " + _enemy + "/" + _maxEnemy;
        money.text = "Money: " + _money;

        if (_hp <= 0)
        {
            Morte();
        }
	}

    public void Morte()
    {
        spawnManager.unRun();
        _enemy = 0;

        GameObject[] e = GameObject.FindGameObjectsWithTag("Enemy");

        foreach (GameObject i in e)
        {
            Destroy(i);
        }

        StatsHover();
    }

    public void StatsHover()
    {
        if (!stats.gameObject.activeInHierarchy)
        {
            stats.showGUI();
        }
    }
	
	public void bankHit (int hit)
	{
		if(_hp > 0)
		{
			_hp -= hit;
		}
	}
	
	public void setMaxEnemy (int i)
	{
		this._maxEnemy = i;
	}
	
	public void setWave (int i)
	{
		this._wave = i;
	}

    public void addGold(int value)
    {
        _money += value;
    }
}
